//
//  RankingListCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/1/30.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "RankingListCell.h"
#import "ImageCollectionCell.h"
@interface RankingListCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic ,strong) UICollectionView *collectionView;
@end
@implementation RankingListCell{
    UIImageView *imageView;
    QXLable     *labName;
    UIButton    *btnCount;
    RankingModel *rankingModel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        WS(weakSelf);
        imageView=[[UIImageView alloc]init];
        [self.contentView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).with.offset(13);
            make.top.equalTo(weakSelf.contentView).with.offset(12.5);
            make.bottom.equalTo(weakSelf.contentView).with.offset(-12.5);
            make.size.mas_offset(CGSizeMake(50, 50));
        }];
        labName=[[QXLable alloc]initTitle];
        [self.contentView addSubview:labName];
        [labName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageView.mas_right).with.offset(20);
            make.top.equalTo(imageView);
        }];
        
        QXLable *lab=[[QXLable alloc]initGaryText];
        lab.text=@"推荐指数:";
        [self.contentView addSubview:lab];
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageView.mas_right).with.offset(20);
            make.bottom.equalTo(imageView);
        }];
        
        [self.contentView addSubview:self.collectionView];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lab.mas_right).with.offset(10);
            make.centerY.equalTo(lab);
            make.size.mas_equalTo(CGSizeMake(200, 30));
        }];
        
        UIView *line=[[UIView alloc]init];
        line.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.equalTo(weakSelf.contentView);
            make.left.equalTo(labName);
            make.height.mas_equalTo(@.7);
        }];
    }
    return self;
}

- (void)setModel:(RankingModel *)model{
    rankingModel=model;
    imageView.image=[UIImage imageNamed:model.image];
    labName.text=model.name;
    
}

#pragma mark - collectionView代理函数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return rankingModel.num;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ImageCollectionCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"ImageCollectionCell" forIndexPath:indexPath];
    [cell setImage:[UIImage imageNamed:@"ranking_star"]];
    return cell;
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        [layout setItemSize:CGSizeMake(15, 15)];
        [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        layout.minimumInteritemSpacing = 5.0;
        layout.minimumLineSpacing = 5.0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.userInteractionEnabled=NO;
        _collectionView.showsHorizontalScrollIndicator=NO;
        [_collectionView registerClass:[ImageCollectionCell class] forCellWithReuseIdentifier:@"ImageCollectionCell"];
    }
    return _collectionView;
}


@end
